package com.zqxq.lottery.entity.o2o.order;

import com.zqxq.common.utils.BigDecimalUtils;
import com.zqxq.common.utils.DispatcherUtils;
import com.zqxq.lottery.entity.po.order.UserOrderPO;
import com.zqxq.lottery.entity.vo.order.UserOrderAPIVO;
import com.zqxq.lottery.entity.vo.order.UserOrderVO;
import org.springframework.util.StringUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Description ：
 * @Author ： 解风
 * @Date ： 2018/03/14 16:12
 */
public class UserOrderO2O {

    public static UserOrderVO toVO(UserOrderPO po) {
        if (po == null) {
            return null;
        }
        UserOrderVO userOrderVO = new UserOrderVO();
        userOrderVO.setId(DispatcherUtils.parseString(po.getId()));
        userOrderVO.setUserId(DispatcherUtils.parseString(po.getUser_id()));
        userOrderVO.setLotteryId(DispatcherUtils.parseString(po.getLottery_id()));
        userOrderVO.setPeriod(po.getPeriod());
        userOrderVO.setBuyWay(DispatcherUtils.parseString(po.getBuy_way()));
        userOrderVO.setPayWay(DispatcherUtils.parseString(po.getPay_way()));
        userOrderVO.setPayAccount(po.getPay_account());
        BigDecimal payAmoutDecimal = BigDecimalUtils.getValue(po.getPay_amount(),2) ;
        String payAmout = payAmoutDecimal == null ? null : payAmoutDecimal.toPlainString();
        userOrderVO.setPayAmount(payAmout);
        BigDecimal prizeDecimal = BigDecimalUtils.getValue(po.getPrize(),2) ;
        String prize = prizeDecimal == null ? null : prizeDecimal.toPlainString();
        userOrderVO.setPrize(prize);
        BigDecimal afterTaxDecimal = BigDecimalUtils.getValue(po.getAfter_tax(),2) ;
        String afterTax = afterTaxDecimal == null ? null : afterTaxDecimal.toPlainString();
        userOrderVO.setAfterTax(afterTax);
        userOrderVO.setStatus(DispatcherUtils.parseString(po.getStatus()));
        userOrderVO.setTicketShow(DispatcherUtils.parseString(po.getTicket_show()));
        userOrderVO.setLotteryNum(po.getLottery_num());
        userOrderVO.setBetNum(DispatcherUtils.parseString(po.getBet_num()));
        userOrderVO.setBetTimes(DispatcherUtils.parseString(po.getBet_times()));
        userOrderVO.setBetBunch(po.getBet_bunch());
        userOrderVO.setBetAppend(DispatcherUtils.parseString(po.getBet_append()));
        userOrderVO.setAppend(DispatcherUtils.parseString(po.getAppend()));
        userOrderVO.setLotteryTime(DispatcherUtils.parseDateTimeStr(po.getLottery_time()));
        userOrderVO.setCreateTime(DispatcherUtils.parseDateTimeStr(po.getCreate_time()));
        userOrderVO.setUpdateTime(DispatcherUtils.parseDateTimeStr(po.getUpdate_time()));
        userOrderVO.setTicketStatus(String.valueOf(po.getTicket_status()));
        userOrderVO.setFollowStatus(String.valueOf(po.getFollow_status()));
        userOrderVO.setIsBonusOptimize(String.valueOf(po.getIs_bonus_optimize()));
        userOrderVO.setBonusOptimizeType(po.getBonus_optimize_type());
        return userOrderVO;
    }

    public static UserOrderPO toPO(UserOrderVO vo) {
        if (vo == null) {
            return null;
        }
        UserOrderPO userOrderPO = new UserOrderPO();
        userOrderPO.setId(DispatcherUtils.parseLong(vo.getId()));
        userOrderPO.setUser_id(DispatcherUtils.parseLong(vo.getUserId()));
        userOrderPO.setLottery_id(DispatcherUtils.parseLong(vo.getLotteryId()));
        userOrderPO.setPeriod(vo.getPeriod());
        userOrderPO.setBuy_way(DispatcherUtils.parseInteger(vo.getBuyWay()));
        userOrderPO.setPay_way(DispatcherUtils.parseInteger(vo.getPayWay()));
        userOrderPO.setPay_account(vo.getPayAccount());
        userOrderPO.setPay_amount(BigDecimalUtils.getBigDecimal(vo.getPayAmount()));
        userOrderPO.setPrize(BigDecimalUtils.getBigDecimal(vo.getPrize()));
        userOrderPO.setAfter_tax(BigDecimalUtils.getBigDecimal(vo.getAfterTax()));
        userOrderPO.setStatus(DispatcherUtils.parseInteger(vo.getStatus()));
        userOrderPO.setTicket_show(DispatcherUtils.parseInteger(vo.getTicketShow()));
        userOrderPO.setLottery_num(vo.getLotteryNum());
        userOrderPO.setBet_num(DispatcherUtils.parseInteger(vo.getBetNum()));
        userOrderPO.setBet_times(DispatcherUtils.parseInteger(vo.getBetTimes()));
        userOrderPO.setBet_bunch(vo.getBetBunch());
        userOrderPO.setBet_append(DispatcherUtils.parseInteger(vo.getBetAppend()));
        userOrderPO.setAppend(DispatcherUtils.parseInteger(vo.getAppend()));
        userOrderPO.setLottery_time(DispatcherUtils.parseDateTime(vo.getLotteryTime()));
        userOrderPO.setCreate_time(DispatcherUtils.parseDateTime(vo.getCreateTime()));
        userOrderPO.setUpdate_time(DispatcherUtils.parseDateTime(vo.getUpdateTime()));
        userOrderPO.setFollow_order_id(DispatcherUtils.parseLong(vo.getFollowOrderId()));
        userOrderPO.setFollow_status(DispatcherUtils.parseInteger(vo.getFollowStatus()));
        userOrderPO.setIs_bonus_optimize(DispatcherUtils.parseInteger(vo.getIsBonusOptimize()));
        userOrderPO.setBonus_optimize_type(vo.getBonusOptimizeType());
        return userOrderPO;
    }

    public static List<UserOrderVO> toVOList(List<UserOrderPO> list){
        List<UserOrderVO> result = new ArrayList<>();
        if(list != null && list.size() > 0){
            for(UserOrderPO po : list) {
                result.add(toVO(po));
            }
        }
        return result;
    }


    public static UserOrderVO apiToVO(UserOrderAPIVO api) {
        if (api == null) {
            return null;
        }
        UserOrderVO userOrderVO = new UserOrderVO();
        userOrderVO.setUserId(api.getUserId());
        userOrderVO.setLotteryId(api.getLotteryId());
        userOrderVO.setPeriod(api.getPeriod());
        userOrderVO.setBuyWay(api.getBuyWay());
        userOrderVO.setPayAmount(api.getPayAmount());
        userOrderVO.setBetNum(api.getBetNum());
        userOrderVO.setBetTimes(api.getBetTimes());
        userOrderVO.setBetBunch(api.getBetBunch());
        userOrderVO.setBetAppend(api.getBetAppend());
        userOrderVO.setAppend(api.getAppend());
        userOrderVO.setRealName(api.getRealName());
        userOrderVO.setMobile(api.getMobile());
        userOrderVO.setIdCard(api.getIdCard());
        userOrderVO.setOrderBetJson(api.getOrderBetJson());
        userOrderVO.setIsPublishFollow(api.getIsPublishFollow());
        userOrderVO.setSecrecySet(api.getSecrecySet());
        userOrderVO.setCommissionRate(api.getCommissionRate());
        userOrderVO.setHeelMultiple(api.getHeelMultiple());
        userOrderVO.setGuaranteeOdds(api.getGuaranteeOdds());
        userOrderVO.setIsBonusOptimize(api.getIsBonusOptimize());
        userOrderVO.setBonusOptimizeBetJson(api.getBonusOptimizeBetJson());
        userOrderVO.setBonusOptimizeType(api.getBonusOptimizeType());
        return userOrderVO;
    }

}
